\input{euler.tex}

\begin{document}

\problem[321]{Swapping Counters}

\solution

Let $n(n+2) = m(m+1)/2$. Rearranging terms, we get
\[
(n+1)^2 - 1 = \frac12 \left[ \left(m+\frac12 \right)^2 - \frac14 \right]
\]
and 
\[
8(n+1)^2 - 8 = (2m+1)^2 - 1
\]
so
\[
(2m+1)^2 - 8(n+1)^2 = -7 
\]
Let $x = 2m+1$ and $y = n+1$, this becomes the Pell equation form
\[
x^2 - 8y^2 = -7
\]

\complexity

Time complexity: $\BigO(d \ln d)$

Space complexity: $\BigO(d)$

\answer

?

\reference


\end{document} 